package com.yuji.aacar.controller.message;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;

import com.yuji.aacar.R;
import com.yuji.aacar.base.BaseActivity;
import com.yuji.aacar.base.UserCenter;
import com.yuji.aacar.bean.beans.PushMessage;
import com.yuji.aacar.bean.response.LoginResponse;
import com.yuji.aacar.controller.adapter.MessageAdapter;
import com.yuji.aacar.widgets.swiplistview.SwipeMenu;
import com.yuji.aacar.widgets.swiplistview.SwipeMenuCreator;
import com.yuji.aacar.widgets.swiplistview.SwipeMenuItem;
import com.yuji.aacar.widgets.swiplistview.WSwipeMenuListView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * <li>Package:com.yuji.aacar.controller.message</li>
 * <li>Author: lining </li>
 * <li>Date: 2018/3/6</li>
 * <li>Description:   </li>
 */

public class MessageActivity extends BaseActivity {


//    @BindView(R.id.title_back)
//    ImageView titleBack;
//    @BindView(R.id.back_image)
//    AutoRelativeLayout backImage;
//    @BindView(R.id.title_content)
//    PingFangTextView titleContent;
//    @BindView(R.id.back_login)
//    PingFangTextView backLogin;
//    @BindView(R.id.title_message_iv)
//    ImageView titleMessageIv;
//    @BindView(R.id.title_message_rl)
//    AutoRelativeLayout titleMessageRl;
//    @BindView(R.id.title_rl)
//    AutoRelativeLayout titleRl;
    @BindView(R.id.message_list)
    WSwipeMenuListView messageList;
    private ArrayList<PushMessage> list;
    private MessageAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_message);
        ButterKnife.bind(this);
        initTitle(true, "消息", null);

       LoginResponse user = UserCenter.getCurrentUser();
        if (null != user){
            list = UserCenter.getPushMessages(user.getMemberId());
        }

//        for (int i = 0; i < 10; i++) {
//            list.add("A5 奥迪进口");
//        }
        adapter = new MessageAdapter(MessageActivity.this, list);
//        creator();
        messageList.setAdapter(adapter);
//        messageList.setOnMenuItemClickListener(new WSwipeMenuListView.OnMenuItemClickListener() {   // ②
//            @Override  // 设置监听事件
//            public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
//                switch (index) {
//                    case 0:  // 在这里写入相应的额逻辑
//                        list.remove(position);
//                        adapter.notifyDataSetChanged();
//                        Toast.makeText(MessageActivity.this, "我打开了", Toast.LENGTH_SHORT).show();
//                        break;
//                    case 1:  // 写入相应的逻辑
//                        list.remove(position);
//                        adapter.notifyDataSetChanged();
//                        Toast.makeText(MessageActivity.this, "我删除了", Toast.LENGTH_SHORT).show();
//                        break;
//                }
//                return false;  // false : close the menu; true : not close the menu
//            }
//        });
        super.onCreate(savedInstanceState);

    }

    private void creator() {
        SwipeMenuCreator creator = new SwipeMenuCreator() {    // SwipeMenuCreator对象的复写方法进行属性设置
            @Override
            public void create(SwipeMenu menu) {
                // 创建删除
                SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
                deleteItem.setBackground(new ColorDrawable(Color.rgb(0xFB, 0x55, 0x57)));//FB5557
                deleteItem.setWidth(315);
                deleteItem.setTitle("删除");
                deleteItem.setTitleColor(Color.WHITE);
                deleteItem.setTitleSize(18);
                menu.addMenuItem(deleteItem);
            }
        };
        messageList.setMenuCreator(creator); // listview 设置 添加creator
        messageList.setSwipeDirection(messageList.DIRECTION_LEFT); // 设置滑出方式为左滑
    }

}
